package com.lingshi.shopping_search_customer_api.controller;


import com.lingshi.shopping.request.GoodsSearchParam;
import com.lingshi.shopping.result.BaseResult;
import com.lingshi.shopping.service.GoodsService;
import com.lingshi.shopping.service.SearchService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/goodsSearch")
public class GoodsSearchController {


    @DubboReference
    private SearchService searchService;

    @DubboReference
    private GoodsService goodsService;

    /**
     * 自动补全功能
     * @param keyword 关键字
     * @return
     */
    @GetMapping("/autoSuggest")
    public BaseResult autoSuggest(String keyword) {
        return BaseResult.success(searchService.autoSuggest(keyword));
    }

    /**
     * 商品搜索功能
     * @param goodsSearchParam 搜索参数对象
     * @return 搜索结果
     */
    @PostMapping("/search")
    public BaseResult search(@RequestBody GoodsSearchParam goodsSearchParam) {
        return BaseResult.success(searchService.search(goodsSearchParam));
    }

    /**
     * 根据商品id查询商品详情
     * @param id 商品id
     * @return
     */
    @GetMapping("/findDesc")
    public BaseResult findDesc(Long id) {
        return BaseResult.success(goodsService.findDesc(id));
    }
}
